﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SCSEngine.Sprite.Implements;
using SCSEngine.Mathematics;
using SVLvsXNA;

namespace TriUan.TriUanGame.Effect
{
    public class StarEffect : Effect
    {
        public StarEffect(GamePage gamePage, Vector2 position, int size, List<string> sprites, bool isTrans, int timeToLive, Color color)
            : base(gamePage, position, size, sprites, isTrans, timeToLive, color)
        {
        }

        public StarEffect(GamePage gamePage, Vector2 position, int size, List<Sprite> sprites, bool isTrans, int timeToLive, Color color)
            : base(gamePage, position, size, sprites, isTrans, timeToLive, color)
        {
        }

        public override void AddNewParticle()
        {
            float velocityAngle = 360.0f / size;
            float originalAngle = 0.0f;
            bool flag = true;
            Vector2 originalVelocity = new Vector2(1f, 1f);

            if (color == Color.White)
            {
                for (int i = 0; i < size; ++i)
                {
                    float angle = MathHelper.ToRadians(originalAngle);
                    originalAngle += velocityAngle;

                    Vector2 velocity = new Vector2();
                    velocity.X = originalVelocity.X * (float)Math.Cos((double)angle);
                    velocity.Y = originalVelocity.Y * (float)Math.Sin((double)angle);

                    flag = !flag;
                    if (flag)
                        velocity *= 5.0f;

                    int TTL = timeToLive;

                    Color ncolor = GRandom.RandomColor();
                    //float angular = MathHelper.ToRadians(30);
                    Particle newParticle = new Particle(this.services, spriteEngine[GRandom.RandomInt(spriteEngine.Count)], originalPos, velocity,
                                                        TTL, ncolor, .0f, 0.0f, Vector2.Zero);
                    particleEngine.Add(newParticle);
                }
            }
            else
            {
                for (int i = 0; i < size; ++i)
                {
                    float angle = MathHelper.ToRadians(originalAngle);
                    originalAngle += velocityAngle;

                    Vector2 velocity = new Vector2();
                    velocity.X = originalVelocity.X * (float)Math.Cos((double)angle);
                    velocity.Y = originalVelocity.Y * (float)Math.Sin((double)angle);

                    flag = !flag;
                    if (flag)
                        velocity *= 2.0f;

                    int TTL = timeToLive;
                    Particle newParticle = new Particle(this.services, spriteEngine[GRandom.RandomInt(spriteEngine.Count)], originalPos, velocity,
                                                        TTL, color, 0.0f, 0.0f, Vector2.Zero);
                    particleEngine.Add(newParticle);
                }
            }
        }
    }

}
